// pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: '',
    dot: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  navEnter(e) {
    let type = e.currentTarget.dataset.type
    let status = this.data.userInfo[`status${type}`]
    if (status == 0) {
      wx.$nav('/pages/enter/enter', {
        type: type
      })
    } else if (status == 1 || status == 3 || status == 2) {
      wx.$nav('/pages/exam/exam', {
        type: type,
        status: status
      })
    } else if (status == 4) {
      if (type == 1) {
        wx.$nav('/pages/workersOrders/wrkersOrders')
      } else {
        wx.$nav('/pages/shop/shop', {
          shopId: this.data.userInfo[`status${type}ShopId`]
        })
      }
    }
  },

  getUser() {
    let that = this
    wx.$https('account.desc').then(res => {
      that.setData({
        userInfo: res
      })
    })
  },

  nav(e) {
    let that = this
    let url = e.currentTarget.dataset.url
    wx.$nav(url)
  },

  navOrder(e) {
    let status = e.currentTarget.dataset.status
    wx.$nav('/pages/orderList/orderList', {
      status: status
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.$isLogin(() => {
      this.getUser()
      this.setData({
        dot: wx.getStorageSync('dot') == 1 ? 1 : 0
      })
      if (this.data.dot == 0) {
        wx.hideTabBarRedDot({
          index: 2,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})